package org.rambadger.command.testing;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class SampleCommandLoader {
    public static List<Object> loadCommands(Readable input) {
        ObjectMapper mapper = new ObjectMapper();
        List<Object> commandList = new ArrayList<>();
        try (Scanner scanner = new Scanner(input)) {
            if (scanner.hasNextLine()) {
                String className = scanner.nextLine();
                String data = scanner.nextLine();
                Class commandClass = Class.forName(className);
                Object newCommand = mapper.readValue(data, commandClass);
                commandList.add(newCommand);
            }
        } catch (Exception e) {
            System.err.println(e);
        }
        return commandList;
    }
}
